local h_util = require "libs/hudutil"
local t_util = require "libs/tableutil"
local e_util = require "libs/entutil"

local r_interval = 1 / 30
local anim_all = {"one", "two", "three", "four", "five", "six", "seven"}
local labels = {}
local point
local function clearAll()
    t_util:IPairs(labels, function(label)
        label:SetText("")
    end)
end
AddPrefabPostInit("archive_orchestrina_small", function(inst)
    inst:DoTaskInTime(0, function()
        local label = h_util:CreateLabel(inst, nil, nil, GLOBAL.CHATFONT_OUTLINE, 40, GLOBAL.PLAYERCOLOURS.GREEN)
        table.insert(labels, label)
        inst:DoPeriodicTask(r_interval, function()
            t_util:Pairs(anim_all, function(order, anim)
                if e_util:IsAnim(anim .. "_pre", inst) then
                    if order == 1 and point ~= inst.GUID then
                        clearAll()
                        point = inst.GUID
                    end
                    label:SetText(order)
                end
            end)
            if e_util:IsAnim("eight_activation", inst) then
                clearAll()
            end
        end)
    end)
end)

AddPrefabPostInit("archive_lockbox_dispencer", function(inst)
    inst:DoTaskInTime(0, function()
        local label = h_util:CreateLabel(inst, nil, {
            x = 0,
            y = 0
        })
        local sym = inst.AnimState:GetSymbolOverride("parts")
        if not sym then
            label:SetText(GLOBAL.STRINGS.NAMES.TURF_ARCHIVE .. "\n" .. GLOBAL.STRINGS.NAMES.TURFCRAFTINGSTATION)
        elseif sym == GLOBAL.hash("archive_knowledge_dispensary_b") then
            label:SetText(GLOBAL.STRINGS.NAMES.ARCHIVE_RESONATOR)
        elseif sym == GLOBAL.hash("archive_knowledge_dispensary_c") then
            label:SetText(GLOBAL.STRINGS.NAMES.REFINED_DUST)
        else
            label:SetText("未知")
        end
    end)
end)
